<template>
  <Modal
    v-model="initOption.visible"
    :title="initOption.title"
    :mask-closable="false">
    <Tree :data="treeData"></Tree>
  </Modal>
</template>
<script>
import fetch from '@/utils/fetch';

export default {
  name: 'treeViewDialog',
  props: {
    initOption: {
      url: {
        type: String,
        required: true
      },
      visible: {
        type: Boolean,
        default: false
      },
      title: {
        type: String,
        default: ''
      }
    }
  },
  data () {
    return {
      treeData: []
    };
  },
  methods: {
    getTreeData () {
      fetch({
        url: this.initOption.url,
        params: {
          id: this.initOption.id
        }
      }).then(response => {
        let obj = response.data;
        if (obj.success) {
          this.treeData = obj.obj;
        } else {
          this.$Notice.error({
            title: '提示',
            desc: obj.msg
          });
        }
      });
    }
  },
  watch: {
    'initOption.visible' (val) {
      if (val) {
        this.getTreeData();
      } else {
        this.treeData = [];
      }
    }
  }
};
</script>
<style scoped>
</style>
